package com.gtt.jr.app;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gtt.jr.app.domain.TypeVO;
import com.gtt.jr.repository.domain.ContainerType;
import com.gtt.jr.service.TypeService;

@Service
public class TypeRepositoryDBImpl implements TypeRepository {

	@Resource
	private TypeService typeService;

	public List<TypeVO> findAll() {
		List<ContainerType> types = typeService.findAll();
		ArrayList<TypeVO> typevos = new ArrayList<TypeVO>();
		for (ContainerType type : types) {
			typevos.add(convert(type));
		}
		return typevos;
	}

	private TypeVO convert(ContainerType type) {
		TypeVO typeVO = new TypeVO();
		typeVO.setId(type.getId());
		typeVO.setName(type.getName());
		return typeVO;
	}

	public TypeVO get(Long id) {
		ContainerType type = typeService.get(id);
		return convert(type);
	}

}
